export const productGetters = {
  allProducts (state) {
    return state.products
  },
  productById: (state, getters) => id => {
    if (getters.allProducts.length > 0) {
      return getters.allProducts.filter(p => p._id === id)[0]
    } else {
      return state.product
    }
  }
}
export const manufacturerGetters = {
  allManufacturers (state) {
    return state.manufacturers
  },
  // 判断本地是否存在该制造商
  manufacturerById: (state, getters) => id => {
    if (getters.allManufacturers.length > 0) {
      return getters.allManufacturers.filter(manufacturer => manufacturer._id === id)[0]
    } else {
      return state.manufacturer
    }
  }
}
